
 /**
 * LoginAction.java.java.
 * User: BrianChen Date: 2012-6-9 下午09:06:43
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.snail.user.action;

import com.collapsar.core.action.BaseStrutsAction;
import com.collapsar.core.security.service.IUserManager;
import com.collapsar.core.util.GlobalConstants;

/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-6-9 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-6-9 下午09:06:43
 * @version 1.0
 * @see
 * 
 */
@SuppressWarnings("serial")
public class LoginAction extends BaseStrutsAction{
	private IUserManager userManager = null;
	private String account = null;
	private String passwd = null;
	
	
	@Override
	public String execute() throws Exception {
		logger.info("###come to loginAction: account="+account+", passwd="+passwd);
		boolean success = this.userManager.login(account, passwd);
		if(success){
			this.request.getSession().setAttribute(GlobalConstants.CURRENT_USER, account);
			this.request.getSession().setAttribute("topMenuId", "sys-home");
			return "index";
		}else{
			String msg = this.userManager.getMessage();
			if(IUserManager.L_USER_NOT_EXIST.equals(msg)){
				this.addFieldError("account", "该用户不存在~！");
				return "user_login";	
			}else if(IUserManager.L_USER_PWD_WRONG.equals(msg)){
				this.addFieldError("passwd", "密码错误~！");
				return "user_login";	
			}else if(IUserManager.L_USER_DISABLE.equals(msg)){
				this.addFieldError("account", "该用户未激活~！");
				return "user_login";		
			}else{
				return null;
			}
		}		
	}

	
	
	//--------------------setters and getters---------------------------------
	public IUserManager getUserManager() {
		return userManager;
	}

	public void setUserManager(IUserManager userManager) {
		this.userManager = userManager;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

}

